package com.demo1105;

import java.util.*;

public class Q3 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long K = sc.nextLong();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        // 单调队列：maxDeque维护窗口最大值（递减），minDeque维护窗口最小值（递增）
        Deque<Integer> maxDeque = new ArrayDeque<>();
        Deque<Integer> minDeque = new ArrayDeque<>();
        int left = 0;
        long count = 0;
        for (int right = 0; right < n; right++) {
            // 维护maxDeque：移除所有小于当前元素的队尾元素，保证队列递减
            while (!maxDeque.isEmpty() && a[maxDeque.peekLast()] <= a[right]) {
                maxDeque.pollLast();
            }
            maxDeque.addLast(right);

            // 维护minDeque：移除所有大于当前元素的队尾元素，保证队列递增
            while (!minDeque.isEmpty() && a[minDeque.peekLast()] >= a[right]) {
                minDeque.pollLast();
            }
            minDeque.addLast(right);

            // 调整左指针，确保当前窗口[left..right]的权值不超过K
            while (true) {
                int currentMax = a[maxDeque.peekFirst()];
                int currentMin = a[minDeque.peekFirst()];
                long diff = currentMax - currentMin;
                int len = right - left + 1;
                if (diff * len > K) {
                    // 左指针右移时，移除不在窗口内的元素
                    if (maxDeque.peekFirst() == left) {
                        maxDeque.pollFirst();
                    }
                    if (minDeque.peekFirst() == left) {
                        minDeque.pollFirst();
                    }
                    left++;
                } else {
                    break;
                }
            }

            // 累加当前右指针对应的有效子数组数量
            count += right - left + 1;
        }

        System.out.println(count);
    }
}
